#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time          : 2024/4/19 15:27
# File          : get_ip_addr.py
# @Author       : MingTai
# @Department   : automation_qa
import socket


def cherry_pick_name():
    print('cherry-pick如何使用')


def get_host_ip():
    global socket_
    try:
        # 创建一个 socket 对象
        socket_ = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # 不发送数据，仅仅是利用这个 socket 对象去尝试连接外网的 DNS 服务器
        socket_.connect(('8.8.8.8', 80))
        # 获取 socket 连接的 IP 地址
        ip = socket_.getsockname()[0]
    finally:
        # 关闭 socket 连接
        socket_.close()

    return ip


if __name__ == '__main__':
    # Running on http://10.121.148.250:17661/
    SERVER_PORT = 5000
    print(f'Running on: http://{get_host_ip()}:{SERVER_PORT}')
    print(f'Running on: http://127.0.0.1:{SERVER_PORT}')
